<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty assign_array function plugin
 * Assign variable into array
 *
 * Examples:
 * <pre>
 * {assign_array var='var_name' value='value'}
 * {assign_array var='var_name' value='value' key='associative key'}
 * </pre>
 *
 * Type:     function<br>
 * Name:     assign_array<br>
 * Purpose:  assign variable into array<br>
 * @author   Novachok Alexandr <novachok@gmail.com>
 * @license http://www.gnu.org/copyleft/gpl.html GPL
 * @param array $params var and value parameters required, key - optinal
 * @param Smarty $smarty
 */
function smarty_function_assign_array($params, &$smarty)
{

  if(empty($params['var']))
  {
    $smarty->trigger_error("var: missing var parameter");
    return;
  }

  if(!isset($params['value']))
  {
    $smarty->trigger_error("value: missing value parameter");
    return;
  }

  $variable = $smarty->get_template_vars($params['var']);
  if(!$variable) $variable = array();

  if(!empty($params['key'])) 
  {
    $key = $params['key'];
  } else
  {
    $key = count($variable);
  }

  $variable[$key] = $params['value'];

  $smarty->assign($params['var'], $variable);
}

/* vim: set expandtab: */

?>